package com.neu.controller;

import com.neu.pojo.RoomType;
import com.neu.service.RoomTypeService;
import com.neu.service.RoomTypeServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.HashMap;
import java.util.List;

@Controller
public class RoomTypeController {
    @Autowired
    private RoomTypeService roomTypeService;

    //根据客房类型名删除客房
    @RequestMapping("delRoomType")
    @ResponseBody
    public HashMap delRoomType(String typeName){
        int res =roomTypeService.delRoomType(typeName);
        HashMap<String,Object> map = new HashMap<>();
        if(res>0) {
            map.put("code", 0);
            map.put("msg", "删除成功");
        }else{
            map.put("code", -1);
            map.put("msg", "删除失败，请稍后重试.");
        }
        return map;
    }

    @RequestMapping("addRoomType")
    @ResponseBody
    public HashMap addRoomType(RoomType roomType){
        int res = roomTypeService.addRoomType(roomType);
        HashMap<String,Object> map = new HashMap<>();
        if(res>0) {
            map.put("code", 0);
            map.put("msg", "新建成功");
        }else{
            map.put("code", -1);
            map.put("msg", "新建失败，请稍后重试.");
        }
        return map;
    }

    @RequestMapping("getRoomTypeByPage")
    @ResponseBody
    public HashMap getRoomTypeByPage(int page,int limit){
        List<RoomType> list=roomTypeService.getRoomTypeByPage(page,limit);
        int totalCount = roomTypeService.getRoomTypeCount();
        HashMap<String,Object> map = new HashMap<>();
        map.put("code",0);
        map.put("msg","success");
        map.put("count",totalCount);
        map.put("data",list);
        return map;

    }

    @RequestMapping("updateRoomType")
    @ResponseBody
    public HashMap updateRoomType(RoomType roomType){
        int res=roomTypeService.updateRoomType(roomType);
        HashMap<String,Object> map = new HashMap<>();
        if(res>0) {
            map.put("code", 0);
            map.put("msg", "更新成功");
        }else{
            map.put("code", -1);
            map.put("msg", "更新失败，请稍后重试.");
        }
        return map;

}


}
